home *** CD-ROM | disk | FTP | other *** search
/ Champak 83 / (Vol 83) My Disc.iso / Games / hello_kitty.swf / scripts / frame_1 / DoAction.as
Text File  |  2008-08-07  |  7KB  |  239 lines

  1. function buildMap(map)
  2. {
  3.    _root.attachMovie("empty","tiles",++d);
  4.    game.clip = _root.tiles;
  5.    game.clip._x = gameInitial_x;
  6.    game.clip._y = gameInitial_y;
  7.    var mapWidth = map[0].length;
  8.    var mapHeight = map.length;
  9.    var i = 0;
  10.    while(i < mapHeight)
  11.    {
  12.       var j = 0;
  13.       while(j < mapWidth)
  14.       {
  15.          var name = "t_" + i + "_" + j;
  16.          game[name] = new game["Tile" + map[i][j]]();
  17.          game.clip.attachMovie("tile",name,i * 100 + j * 2);
  18.          game.clip[name]._x = j * game.tileW;
  19.          game.clip[name]._y = i * game.tileH;
  20.          game.clip[name].gotoAndStop(game[name].frame);
  21.          j++;
  22.       }
  23.       i++;
  24.    }
  25.    game.items = myItems;
  26.    var i = 0;
  27.    while(i < game.items.length)
  28.    {
  29.       var name = "item" + game.items[i][2] + "_" + game.items[i][1];
  30.       game[name] = new game["Item" + game.items[i][0]]();
  31.       game[name].position = i;
  32.       game.clip.attachMovie("item",name,10001 + i);
  33.       game[name].clip = game.clip[name];
  34.       game[name].clip._x = game.items[i][1] * game.tileW + game.tileW / 2;
  35.       game[name].clip._y = game.items[i][2] * game.tileH + game.tileH / 2;
  36.       game[name].clip.gotoAndStop(game.items[i][0]);
  37.       i++;
  38.    }
  39.    _root.points = game.points;
  40.    var enemies = myEnemies;
  41.    game.currentEnemies = enemies.length;
  42.    var i = 0;
  43.    while(i < game.currentEnemies)
  44.    {
  45.       var name = "enemy" + i;
  46.       game[name] = new game["Enemyp" + enemies[i][0]]();
  47.       game.clip.attachMovie("enemy1",name,10012 + i);
  48.       game[name].clip = game.clip[name];
  49.       game[name].xtile = enemies[i][1];
  50.       game[name].ytile = enemies[i][2];
  51.       game[name].width = game.clip[name]._width / 2;
  52.       game[name].height = game.clip[name]._height / 2;
  53.       game[name].x = game[name].xtile * game.tileW + game.tileW / 2;
  54.       game[name].y = game[name].ytile * game.tileH + game.tileH / 2;
  55.       game[name].clip._x = game[name].x;
  56.       game[name].clip._y = game[name].y;
  57.       i++;
  58.    }
  59.    game.clip.attachMovie("char","char",1000);
  60.    char.clip = game.clip.char;
  61.    char.x = char.xtile * game.tileW + game.tileW / 2;
  62.    char.y = char.ytile * game.tileH + game.tileH / 2;
  63.    char.width = char.clip._width / 2;
  64.    char.height = char.clip._height / 2;
  65.    char.clip._x = char.x;
  66.    char.clip._y = char.y;
  67. }
  68. function enemyBrain()
  69. {
  70.    var i = 0;
  71.    while(i < 5)
  72.    {
  73.       var name = "enemy" + i;
  74.       var ob = game[name];
  75.       getMyCorners(ob.x + ob.speed * ob.xMove,ob.y + ob.speed * ob.yMove,ob);
  76.       if(ob.downleft and ob.upleft and ob.downright and ob.upleft)
  77.       {
  78.          moveChar(ob,ob.xMove,ob.yMove);
  79.       }
  80.       else
  81.       {
  82.          ob.xMove = - ob.xMove;
  83.          ob.yMove = - ob.yMove;
  84.       }
  85.       if(!_root.infiniteLife)
  86.       {
  87.          var xdist = ob.x - char.x;
  88.          var ydist = ob.y - char.y;
  89.          if(math.sqrt(xdist * xdist + ydist * ydist) < ob.width + char.width)
  90.          {
  91.             _root.lifes -= 1;
  92.             mylifes.gotoAndStop(_root.lifes);
  93.             if(lifes == 0)
  94.             {
  95.                removeMovieClip(_root.tiles);
  96.                _root.gotoAndStop(35);
  97.             }
  98.             if(!_root.hurt)
  99.             {
  100.                char.clip.gotoAndPlay("hurt");
  101.                return undefined;
  102.             }
  103.          }
  104.       }
  105.       i++;
  106.    }
  107. }
  108. function starting_point()
  109. {
  110.    char.x = startingXtile * game.tileW + game.tileW / 2;
  111.    char.y = startingYtile * game.tileH + game.tileH / 2;
  112.    char.clip._x = char.x;
  113.    char.clip._y = char.y;
  114. }
  115. function detectKeys()
  116. {
  117.    var ob = _root.char;
  118.    var keypressed = false;
  119.    if(key.isDown(39))
  120.    {
  121.       keyPressed = _root.moveChar(ob,1,0);
  122.    }
  123.    else if(key.isDown(37))
  124.    {
  125.       keyPressed = _root.moveChar(ob,-1,0);
  126.    }
  127.    else if(key.isDown(38))
  128.    {
  129.       keyPressed = _root.moveChar(ob,0,-1);
  130.    }
  131.    else if(key.isDown(40))
  132.    {
  133.       keyPressed = _root.moveChar(ob,0,1);
  134.    }
  135.    if(!KeyPressed)
  136.    {
  137.       ob.clip.mychar.gotoAndStop(1);
  138.    }
  139.    else
  140.    {
  141.       ob.clip.mychar.play();
  142.    }
  143.    enemyBrain();
  144. }
  145. function moveChar(ob, dirx, diry)
  146. {
  147.    getMyCorners(ob.x,ob.y + ob.speed * diry,ob);
  148.    if(diry == -1)
  149.    {
  150.       if(ob.upleft and ob.upright)
  151.       {
  152.          ob.y += ob.speed * diry;
  153.       }
  154.       else
  155.       {
  156.          ob.y = ob.ytile * game.tileH + ob.height;
  157.       }
  158.    }
  159.    if(diry == 1)
  160.    {
  161.       if(ob.downleft and ob.downright)
  162.       {
  163.          ob.y += ob.speed * diry;
  164.       }
  165.       else
  166.       {
  167.          ob.y = (ob.ytile + 1) * game.tileH - ob.height;
  168.       }
  169.    }
  170.    getMyCorners(ob.x + ob.speed * dirx,ob.y,ob);
  171.    if(dirx == -1)
  172.    {
  173.       if(ob.downleft and ob.upleft)
  174.       {
  175.          ob.x += ob.speed * dirx;
  176.       }
  177.       else
  178.       {
  179.          ob.x = ob.xtile * game.tileW + ob.width;
  180.       }
  181.    }
  182.    if(dirx == 1)
  183.    {
  184.       if(ob.upright and ob.downright)
  185.       {
  186.          ob.x += ob.speed * dirx;
  187.       }
  188.       else
  189.       {
  190.          ob.x = (ob.xtile + 1) * game.tileW - ob.width;
  191.       }
  192.    }
  193.    ob.clip._x = ob.x;
  194.    ob.clip._y = ob.y;
  195.    ob.clip.gotoAndStop(dirx + diry * 2 + 3);
  196.    ob.xtile = Math.floor(ob.clip._x / game.tileW);
  197.    ob.ytile = Math.floor(ob.clip._y / game.tileH);
  198.    var itemname = game["item" + ob.ytile + "_" + ob.xtile];
  199.    if(itemname and ob == _root.char)
  200.    {
  201.       game.points = true;
  202.       removeMovieClip(itemname.clip);
  203.       game.items[itemname.position] = 0;
  204.       delete game["item" + ob.ytile + "_" + ob.xtile];
  205.       if(game.points = true)
  206.       {
  207.          opendoorname = "t_" + unlockY + "_" + unlockX;
  208.          game.clip[opendoorname].gotoAndStop(4);
  209.          game.Tile2.prototype.walkable = true;
  210.       }
  211.    }
  212.    if(_root.char.ytile == unlockY && _root.char.xtile == unlockX && _root.unlock)
  213.    {
  214.       removeMovieClip(_root.tiles);
  215.       _root.unlock = false;
  216.       _root.nextFrame();
  217.    }
  218.    return true;
  219. }
  220. function getMyCorners(x, y, ob)
  221. {
  222.    ob.downY = Math.floor((y + ob.height - 1) / game.tileH);
  223.    ob.upY = Math.floor((y - ob.height) / game.tileH);
  224.    ob.leftX = Math.floor((x - ob.width) / game.tileW);
  225.    ob.rightX = Math.floor((x + ob.width - 1) / game.tileW);
  226.    ob.upleft = game["t_" + ob.upY + "_" + ob.leftX].walkable;
  227.    ob.downleft = game["t_" + ob.downY + "_" + ob.leftX].walkable;
  228.    ob.upright = game["t_" + ob.upY + "_" + ob.rightX].walkable;
  229.    ob.downright = game["t_" + ob.downY + "_" + ob.rightX].walkable;
  230. }
  231. gameInitial_x = 75;
  232. gameInitial_y = 106;
  233. hurt = false;
  234. unlock = false;
  235. lifes = 4;
  236. infiniteLife = false;
  237. stop();
  238. var tempLv = 0;
  239.